//
//  WJMineOperationCell.swift
//  PDFSign
//
//  Created by 李永彬 on 2025/9/29.
//

import UIKit
import SnapKit

class WJMineOperationCell: UITableViewCell {
    
    // MARK: - Lazy Components
    
    /// 左侧图标
    private lazy var leftIcon: UIImageView = {
        let iv = UIImageView()
        iv.contentMode = .scaleAspectFit
        iv.tintColor = .darkGray
        return iv
    }()
    
    /// 中间标题
    private lazy var titleLabel: UILabel = {
        let label = UILabel()
        label.font = UIFont.systemFont(ofSize: 16)
        label.textColor = UIColor(hex: "#121212")
        return label
    }()
    
    /// 右侧箭头图标
    private lazy var rightArrow: UIImageView = {
        let iv = UIImageView()
        iv.image = UIImage(named: "Icon_line_click")
        iv.tintColor = .lightGray
        iv.contentMode = .scaleAspectFit
        return iv
    }()
    
    /// 分割线
    private lazy var separatorLine: UIView = {
        let view = UIView()
        view.backgroundColor = UIColor(hex: "#121212", alpha: 0.05)
        return view
    }()
    
    // MARK: - Initialization
    
    override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        setupUI()
        setupConstraints()
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    // MARK: - Setup
    
    private func setupUI() {
        backgroundColor = .clear
        selectionStyle = .none
        
        // 添加子视图
        contentView.backgroundColor = UIColor(hex: "#FFFFFF")
        contentView.addSubview(leftIcon)
        contentView.addSubview(titleLabel)
        contentView.addSubview(rightArrow)
        contentView.addSubview(separatorLine)
    }
    
    private func setupConstraints() {
        // 左侧图标约束
        leftIcon.snp.makeConstraints { make in
            make.left.equalToSuperview().offset(20)
            make.centerY.equalToSuperview()
            make.width.height.equalTo(24)
        }
        
        // 标题约束
        titleLabel.snp.makeConstraints { make in
            make.left.equalTo(leftIcon.snp.right).offset(12)
            make.centerY.equalToSuperview()
        }
        
        // 右侧箭头约束
        rightArrow.snp.makeConstraints { make in
            make.right.equalToSuperview().offset(-20)
            make.centerY.equalToSuperview()
            make.width.height.equalTo(20)
        }
        
        // 分割线约束
        separatorLine.snp.makeConstraints { make in
            make.leading.equalToSuperview().offset(16)
            make.trailing.equalToSuperview().offset(-16)
            make.bottom.equalToSuperview()
            make.height.equalTo(1.0)
        }
    }
    
    // MARK: - Public Methods
    
    /// 配置单元格内容
    func configure(with title: String, icon: UIImage?, isLastCell: Bool = false) {
        titleLabel.text = title
        leftIcon.image = icon
        
        // 设置分割线显示状态
        separatorLine.isHidden = isLastCell
    }
    
    /// 配置单元格内容（使用系统图标）
    func configure(with title: String, systemImageName: String, isLastCell: Bool = false) {
        titleLabel.text = title
        leftIcon.image = UIImage(systemName: systemImageName)
        
        // 设置分割线显示状态
        separatorLine.isHidden = isLastCell
    }
}
